package com.lbssoft.gpsbd.controller;

import com.lbssoft.gpsbd.model.Result;
import com.lbssoft.gpsbd.service.EventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Api("消息事件")
@RestController
@RequestMapping(value="/events")
@Validated
public class EventsController {
	@Autowired
	EventService eventService;


	@ApiOperation(value="查询消息", notes="获取用户下所有设备的消息")
	@RequestMapping(value = "",method = {RequestMethod.GET})
	@ResponseBody
	public Result list(@NotNull @RequestParam(value = "page", defaultValue = "1") int page,
					   @NotNull @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {

		return eventService.getEvents(page,pageSize);
	}


	@ApiOperation(value="设置状态为已读", notes="设置设备消息为已读")
	@RequestMapping(value = "/{id}",method = {RequestMethod.GET})
	@ResponseBody
	public Result read(@NotNull @PathVariable long id) {
		return eventService.readEvent(id);
	}

	@ApiOperation(value="删除事件", notes="根据事件id删除事件")
	@RequestMapping(value = "/{id}",method = {RequestMethod.DELETE})
	@ResponseBody
	public Result delete(@NotNull @PathVariable long id) {
		return eventService.delete(id);
	}
	
}